<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if(!class_exists('Api_youku_answer')){
	class Api_youku_answer extends CI_Controller {

		public function __construct(){
			parent::__construct();
            $this->load->model('Appmodel','m_app');
            $this->load->model('Apilogmodel','m_api_log');
			$this->load->model('Youkuanswermodel','m_answer');
			$this->load->database();
		}

        public function __destruct() {
            // $this->session->unset_userdata($this->_action);
            // //api开头的不存
            if(is_string($this->uri->rsegments[2]) && stripos($this->uri->rsegments[2], 'api') === 0) {
            	$this->db->close();
                return;
            }
            $customer = $this->session->userdata('marathon_customer');
            $info = $this->input->post();
            $result = $this->response->getResult();
            @$this->m_api_log->createApiLog(array(
                'ip_address' => $this->input->ip_address(),
                'customer_id' => empty($customer) ? 0 :  $customer['customer_id'],
                'request_uri' => $_SERVER['REQUEST_URI'],
                'post_data' => json_encode($info,JSON_UNESCAPED_UNICODE),
                'result_data' => json_encode($result,JSON_UNESCAPED_UNICODE),
                'api_log_time_create' => NOW,
                'ua' => empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'],
                // 'terminal' => TERMINAL_WEIXIN,
            ));

            $this->db->close();
        }

        public function submitAnswer() {
            $this->validate->setRule('answer0','string');
            $this->validate->setRule('answer1','string');
            $this->validate->setRule('answer2','string');
            $this->validate->setRule('answer3','string');
            $this->validate->setRule('answer4','string');
            $this->validate->setRule('answer5','string');
            $this->validate->setRule('answer6','string');
            $this->validate->setRule('answer7','string');
            $this->validate->setRule('answer8','string');
            $this->validate->setRule('answer9','string');
            $this->validate->setRule('answer_result','string');
            if(!$this->validate->run($this->input->post(),true)){
                $this->response->setDetail($this->validate->getMessage());
                $this->response->responseExit();
            }
            $info = $this->validate->getResult();

            $info['answer_time_create'] = NOW;
            $this->m_answer->createAnswer($info);

            $this->response->setSuccess();
            $this->response->responseExit();
        }

	}
}

/* End of file pc_controller.php */
/* Location: ./application/controllers/pc_controller.php */
